package com.yanming.demo.controller;

import com.yanming.demo.core.response.RestResult;
import com.yanming.demo.core.response.RestResultElementui;
import com.yanming.demo.model.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @description: User 控制器
 */
@RestController
@RequestMapping("/user")
public class UserController {
	private final Logger logger = LoggerFactory.getLogger(UserController.class);

	/**
	 * @description : 通过id获取User
	 * 
	 * @author : YanMing(by4044)
	 * @since : Create in 2019-06-13
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ResponseBody
	public RestResult<List<User>> getList(String id) {
		try {
			List<User> userList=new ArrayList<>();
			for(int i=0;i<10;i++){
				User user = new User();
				user.setName("小虎"+i);
				user.setDate(new Date());
				user.setAddress("深圳市南山区软件产业基地"+i);
				userList.add(user);
			}

			return new RestResult<List<User>>(0,"成功",userList );
		} catch (Exception e) {
			logger.info("异常信息:{}" + e.getMessage());
			// 异常
			return new RestResult<List<User>>(-1, "异常信息:{" + e.getClass().getName() + "}");
		}
	}

	@RequestMapping(value = "/page", method = RequestMethod.GET)
	@ResponseBody
	public RestResultElementui<User> page() {
		RestResultElementui<User> page = new RestResultElementui<User>(1,"无数据");
		try {
			List<User> userList=new ArrayList<>();
			for(int i=0;i<10;i++){
				User user = new User();
				user.setName("小虎"+i);
				user.setDate(new Date());
				user.setAddress("深圳市南山区软件产业基地"+i);
				userList.add(user);
			}
			page = new RestResultElementui<User>(1,10,10,userList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}

}